package cn.kgc.ssm.web.service.impl;

import cn.kgc.ssm.web.entity.Active;
import cn.kgc.ssm.web.mapper.ActiveMapper;
import cn.kgc.ssm.web.response.ResponseResult;
import cn.kgc.ssm.web.service.ActiveService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/8/5
 * @description
 */
@Service
public class ActiveServiceImpl implements ActiveService {

    @Autowired
    private ActiveMapper activeMapper;


    @Override
    public ResponseResult activeList(Integer limit) {

        List<Active> actives = activeMapper.selectActiveList(limit);

        return ResponseResult.success().data(actives);
    }

    @Override
    public ResponseResult activePage(Integer page, Integer limit, String publisher) {

        PageHelper.startPage(page, limit);
        List<Active> actives = activeMapper.selectActivePage(publisher);
        long total = new PageInfo<Active>(actives).getTotal();

        return ResponseResult.success().data(actives).count(total);
    }

    @Override
    public ResponseResult publishActive(Active active) {

        activeMapper.addActive(active);

        return ResponseResult.success();
    }

    @Override
    public ResponseResult editActive(Active active) {

        activeMapper.updateActive(active);
        return ResponseResult.success();
    }

    @Transactional
    @Override
    public ResponseResult deleteActive(List<Integer> ids) {

        activeMapper.deleteActive(ids);
        return ResponseResult.success();
    }
}
